package tags;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import beans.Distrito;
import dao.interfaces.DistritoDAO;
import factory.Factory;

public class DistritoTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	public int doStartTag() throws JspException{
			
		try {
			JspWriter out = pageContext.getOut();
			
			/*Se invoca a la facbrica MySql*/
			Factory factory = Factory.obtenerTipo(2);
			DistritoDAO didao = factory.obtenerDistritoDAO();
			
			List<Distrito> lista = didao.ListarDistrito();
			
			/*Se crea el control select*/
			out.write("<select id = 'cboDistrito' name='cboDistrito'>") ;
			out.write("<option>--Seleccione--</option>");
					for (Distrito d : lista) {
						out.write("<option value='"+d.getId()+"'>"+
								d.getNombre()+
								"</option>");
					}
			out.write("</select>");
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		return SKIP_BODY;
	}
	
	@Override
	public int doEndTag() throws JspException{
		return EVAL_PAGE;
	}
}
